package com.syl.starter.itools.base.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;

/**
 *  流关闭工具类
 * @author syl
 * @create 2018-09-15 16:23
 **/
public class CloseUtils {
    private static Logger LOG = LoggerFactory.getLogger(CloseUtils.class);

    /**
     * 关闭流
     * @param closeable
     */
    public static void close(Closeable closeable){
        try {
            //输入流关闭
            if(closeable != null)
                closeable.close();
        } catch (Exception e) {
            LogUtils.error(LOG,"输入流关闭异常",e);
        }
    }

    /**
     * 按顺序关闭所有流 先开的后关
     * @param closeables
     */
    public static void closeAll(Closeable... closeables){
        for (Closeable closeable : closeables) {
            close(closeable);
        }
    }

}
